'use strict';
module.exports = function(sequelize, DataTypes) {
  var product = sequelize.define('product', {
    id: {
      type: DataTypes.UUID,
      primaryKey: true,
      defaultValue: DataTypes.UUIDV1
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
      validate: {
        notEmpty: true
      }
    },
    subtitle: DataTypes.STRING,
    description: DataTypes.TEXT,
    unitPrice: {
      type: DataTypes.DECIMAL(10, 2),
      validate: {
        isDecimal: true
      }
    },
    quantitySold: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      allowNull: false,
      validate: {
        isInt: true
      }
    },
    ranking: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    isPopular: {
      type: DataTypes.BOOLEAN,
      defaultValue: false
    }
  }, {
    classMethods: {
      associate: function(models) {
        // associations can be defined here
        product.belongsToMany(models.profile, {
          through: models.cart
        });
      }
    },
    paranoid: true
  });
  return product;
};
